<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
 
class b2c_ctl_admin_synerrorlog extends desktop_controller{

    var $workground = 'b2c_ctl_admin_order';
    
    /**
     * 构造方法
     * @params object app object
     * @return null
     */
    public function __construct($app)
    {
        parent::__construct($app);
        header("cache-control: no-store, no-cache, must-revalidate");
    }

    function index(){

        $this->finder('b2c_mdl_synerrorlog',array(
            'title'=>app::get('b2c')->_('同步异常订单'),
            'allow_detail_popup'=>true,
            'use_buildin_recycle'=>false,
            'use_view_tab'=>true,

            'use_buildin_new_dialog' => false,
            'use_buildin_set_tag' => false,
            'use_buildin_recycle' => false,
            'use_buildin_export' => true ,
            'use_buildin_import' => false,
            'use_buildin_filter' => true,
            'allow_detail_popup' => true,
            'max_actions' => 8,
            'use_view_tab' => true,
            'actions' => array(
              'delete' => array(
                    'label' => '删除',
                    'submit' => 'index.php?app=b2c&ctl=admin_synerrorlog&act=doDelete',
                ),
              ),
            ));


    }

    /**
     * view 列表
     * @param null
     * @return null
     */
    public function _views(){
        // $mdl_synerrorlog = $this->app->model('synerrorlog');
        // $sub_menu = array(
        //     0=>array('label'=>app::get('b2c')->_('未处理'),'optional'=>false,'filter'=>array('Issyn'=>'false')),
        //     1=>array('label'=>app::get('b2c')->_('已处理'),'optional'=>false,'filter'=>array('Issyn'=>'true')),
        // );

        // if(isset($_GET['optional_view'])) $sub_menu[$_GET['optional_view']]['optional'] = false;

        // foreach($sub_menu as $k=>$v){
        //     if($v['optional']==false){
        //         $show_menu[$k] = $v;
        //         if(is_array($v['filter'])){
        //             $v['filter'] = array_merge(array(),$v['filter']);
        //         }else{
        //             $v['filter'] = array();
        //         }
        //         $show_menu[$k]['filter'] = $v['filter']?$v['filter']:null;
        //         if($k==$_GET['view']){
        //             $show_menu[$k]['newcount'] = true;
        //             $show_menu[$k]['addon'] = $mdl_synerrorlog->count($v['filter']);
        //         }
        //         $show_menu[$k]['href'] = 'index.php?app=b2c&ctl=admin_synerrorlog&act=index&view='.($k).(isset($_GET['optional_view'])?'&optional_view='.$_GET['optional_view'].'&view_from=dashboard':'');
        //     }elseif(($_GET['view_from']=='dashboard')&&$k==$_GET['view']){
        //         $show_menu[$k] = $v;
        //     }
        // }
        // return $show_menu;
    }


    function exec($cron_id,$order_id) {
        $this->begin('');
        $model = app::get('base')->model('crontab');
        $cron = $model->getRow('id', array('id'=>$cron_id));
        if(!$cron || (base_crontab_schedule::trigger_one($cron['id'])===false)) {
            $this->end(false, '执行失败');
        }
        else{
            $synerrorlog=app::get('b2c')->model('synerrorlog');
            $synerrorlog->db->exec("update sdb_b2c_synerrorlog set Issyn='true' where DocNo=$order_id");
            $this->end(true, '执行成功');
        }
    }


//删除
   function doDelete()
    {
  
       $this->begin("index.php?app=b2c&ctl=admin_synerrorlog&act=index");
        $this->_request    = kernel::single('base_component_request');
        $order_info        = $this->_request->get_post();
        $userinfo_model = $this->app->model('synerrorlog');


        foreach ($order_info['log_id'] as $key => $value) 
        {
            $orders = $userinfo_model->getList('*', array('log_id'=>$value), 0, 1);
            
           $userinfo_model->db->exec("delete from sdb_b2c_synerrorlog where log_id in(".$value.")");
 
        }
        $this->end(true, '删除成功'); 
       
    }

}
